package com.cuz.series.linklist;

public class 链表3打印两个有序链表的相同部分 {

    public static void main(String[] args) {
        ListNode node = ListNode.of1(1, 2, 3, 5, 6);
        ListNode node1 = ListNode.of1(2, 4, 5, 6, 7);
        print(node1,node);
    }
    public static void print(ListNode l1, ListNode l2) {
        StringBuilder sb = new StringBuilder();
        while (l1 != null && l2 != null) {
            if (l1.val == l2.val) {
                sb.append(l1.val).append("-");
                l1 = l1.next;
                l2 = l2.next;
                continue;
            }

            if (l1.val < l2.val) {
                l1 = l1.next;
            } else {
                l2 = l2.next;
            }
        }
        System.out.println(sb);
    }
}
